package com.ctbu.score.aspect;

import com.ctbu.score.exception.RException;
import com.ctbu.score.helper.Result;
import com.ctbu.score.helper.ResultUtil;
import org.springframework.web.bind.annotation.ExceptionHandler;
import org.springframework.web.bind.annotation.RestControllerAdvice;

/**
 * 统一异常处理，使用ControllerAdvice（增强控制器）
 */
@RestControllerAdvice
public class ExceptionHandle {
    @ExceptionHandler(value=Exception.class)
    public Result handle(Exception e) {
        if(e instanceof RException){
            RException re = (RException) e;
            return ResultUtil.error(re.getCode(),re.getMessage());
        }
        return  ResultUtil.error(-999,e.getMessage());
    }
}
